package com.java.dormitorymanager.mvc.view;

import com.java.dormitorymanager.pojo.Manager;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;

/**
 * @program: DormitoryManager
 * @description: 超管管理宿管界面
 * @author: ShuangChenYue
 * @create: 2021-05-15 22:08
 **/

@WebServlet(value = "/ViewManageCommonManager")
public class ViewManageCommonManagerServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("点击宿管按钮请求转发至此ViewManageCommonManager");
        req.setCharacterEncoding("utf-8");
        resp.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>管理宿管界面</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-manager/manageCommonManager.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Dorm Manager</h1>");
        out.println("</div>");
        out.println("<div id=\"div02\">");
        out.println("<form action=\"/DormitoryManager/mvc/searchCMByName.do\" method=\"post\">");
        out.println("<input id=\"inputSearch01\" type=\"text\" name=\"name\" placeholder=\"输入姓名查找宿管\"><input class=\"iconfontU\" id=\"inputSearch02\" type=\"submit\" name=\"search\" value=\"&#xe632;\" title=\"点击搜索\">");
        out.println("</form>");
        out.println("</div>");
        out.println("<div id=\"div01\">");
        out.println("<h3 class=\"ListName\">DormManagerList</h3>");
        out.println("<a  class=\"iconfontU addIcon\" title=\"添加宿管\" href=\"/DormitoryManager/ViewAddCM\" target=\"_blank\">&#xe621;</a>");
        out.println("<table class=\"table01\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>密码</td>");
        out.println("<td>权限</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");
        List<Manager> allCommonManagerList = (List<Manager>) req.getAttribute("allCommonManagerList");
        Iterator<Manager> iterator = allCommonManagerList.iterator();
        while (iterator.hasNext())
        {
            Manager commonManager = iterator.next();
            out.println("<tr class=\"tr02\">");
            out.println("<td style=\"text-align: center\">"+commonManager.getId()+"</td>");
            out.println("<td>"+commonManager.getName()+"</td>");
            out.println("<td>"+commonManager.getPassword()+"</td>");
            out.println("<td>"+commonManager.getStatus()+"</td>");
            out.println("<td><a href=\"/DormitoryManager/mvc/toUpdateCMDetail.do?id="+commonManager.getId()+"\"><i class=\"iconfontU alterIcon\" title=\"修改\">&#xe700;</i></a> <a href=\"/DormitoryManager/mvc/deleteCommonManagerById.do?id="+commonManager.getId()+"\"><i class=\"iconfontU deleteIcon\" title=\"删除\">&#xe614;</i></a> <a href=\"/DormitoryManager/mvc/bannedCommonManager.do?id="+commonManager.getId()+"\"><i class=\"iconfontU bannedIcon\" title=\"停用\">&#xe61a;</i></a></td>");
            out.println("</tr>");
        }
        out.println("</table>");
//=======================================================被禁用的宿管====================================================
        out.println("<h3 class=\"ListName\">Banned</h3>");
        out.println("<table class=\"table01\" style=\"color: #a5a5a5\">");
        out.println("<tr class=\"tr01\">");
        out.println("<td>ID</td>");
        out.println("<td>姓名</td>");
        out.println("<td>密码</td>");
        out.println("<td>权限</td>");
        out.println("<td>操作</td>");
        out.println("</tr>");

        List<Manager> allBannedManagerList = (List<Manager>) req.getAttribute("allBannedManagerList");
        Iterator<Manager> iterator1 = allBannedManagerList.iterator();
        while (iterator1.hasNext())
        {
            Manager bannedManager = iterator1.next();
            out.println("<tr class=\"tr02\">");
            out.println("<td style=\"text-align: center\">"+bannedManager.getId()+"</td>");
            out.println("<td>"+bannedManager.getName()+"</td>");
            out.println("<td>"+bannedManager.getPassword()+"</td>");
            out.println("<td>"+bannedManager.getStatus()+"</td>");
            out.println("<td><a href=\"/DormitoryManager/mvc/deleteBannedManagerById.do?id="+bannedManager.getId()+"\"><i class=\"iconfontU deleteIcon\" title=\"删除\">&#xe614;</i></a> <a href=\"/DormitoryManager/mvc/openBannedManagerById.do?id="+bannedManager.getId()+"\"><i class=\"iconfontU bannedIcon\" title=\"启用\">&#xe6ed;</i></a></td>");
            out.println("</tr>");
        }

        out.println("</table>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
